using System;

namespace MiniFlower
{
    public class Player
    {
        protected PlayerControllerBase m_Controller;

        public PlayerControllerBase GetPlayerController(IGameWorld world)
        {
            if(world == null)
            {
                return m_Controller;
            }

            PlayerControllerBase controller = world.GetPlayerController();

            if(controller.Player == this)
            {
                return controller;
            }

            return null;
        }

        public void SwitchController(PlayerControllerBase controller)
        {
            if(controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

            m_Controller?.SetPlayer(null);

            controller.SetPlayer(this);
            m_Controller = controller;
        }
    }
}
